﻿/*************************************
 * Creator:SunnyPaine
 * DateTime:2022/8/22 15:21:52
 * Description:<Description>
 * CopyRight:
 * ***********************************/

using Autofac.Core;
using SunnyPaine.Autofac.Extension.Stereotype.Attributes;
using System.Linq;
using System.Reflection;

namespace SunnyPaine.SqlSugar.Autofac.Stereotype.Selector
{
    /// <summary>
    /// 根据类型注入属性的选择器。
    /// </summary>
    public class AutowiredPropertySelector : IPropertySelector
    {
        /// <summary>
        /// 属性过滤。
        /// </summary>
        /// <param name="propertyInfo"></param>
        /// <param name="instance"></param>
        /// <returns></returns>
        public bool InjectProperty(PropertyInfo propertyInfo, object instance)
        {
            return propertyInfo.CustomAttributes.Any(it => it.AttributeType == typeof(AutowiredAttribute));
        }
    }
}
